import React, {PureComponent} from "react";
import {connect} from "react-redux";
import {Button, Modal, notification} from "antd";
import {hideModify, query} from "./actions";
import FormEditor from '../../components/FormEditor';
import {DATE_FORMAT} from "../../lib/func";
import {getPrincipal} from "../../lib/identity";

class ModifyModal extends PureComponent {


    handleCancel = () => {
        const {dispatch} = this.props;
        dispatch(hideModify());
    };


    render() {
        const {loading, visible, model} = this.props;
        if (model.startTime && model.endTime) {
            model.dateRange1 = model.startTime.substring(0, 10) + "至" + model.endTime.substring(0, 10)
        }
        const schema = [
            {
                title: '基础信息',
                fields: [
                    {
                        field: 'title',
                        title: '标题',
                        type: 'text',
                        fieldOptions: {
                            rules: [{required: true, message: '请输入标题'}]
                        }
                    }, {
                        field: 'description',
                        title: '内容',
                        type: 'textArea',
                        fieldOptions: {
                            rules: [{required: true, message: '请输入内容'}]
                        }
                    }, {
                        field: 'dateRange1',
                        title: '公告时间',
                        readonly: true
                    }
                ]
            }];

        return (
            <Modal
                title="详情"
                visible={visible}
                onCancel={this.handleCancel}
                confirmLoading={loading}
                footer={null}
                width="40%"
            >
                <FormEditor
                    schema={schema}
                    column={1}
                    defaultReadonly={true}
                    showActionBar={false}
                    defaultValues={model}
                    wrappedComponentRef={inst => (this.formEditor = inst)}
                />
            </Modal>

        );
    }
}

const mapStateToProps = state => {
    return {
        ...state.historyNotice.modify,
        organizations: state.home.organizations
    };
};

export default connect(mapStateToProps)(ModifyModal);
